﻿using System;
using System.Text;
using GeoAPI.Geometries;
using NetTopologySuite.Utilities;

namespace NetTopologySuite.Geometries
{
	[Obsolete("No longer used.")]
	[Serializable]
	public class DefaultCoordinateSequence : ICoordinateSequence, ICloneable
	{
		public DefaultCoordinateSequence(Coordinate[] coordinates)
		{
			if (Geometry.HasNullElements(CollectionUtil.Cast<Coordinate, object>(coordinates)))
			{
				throw new ArgumentException("Null coordinate");
			}
			this._coordinates = coordinates;
		}

		public DefaultCoordinateSequence(ICoordinateSequence coordSeq)
		{
			this._coordinates = new Coordinate[coordSeq.Count];
			for (int i = 0; i < this._coordinates.Length; i++)
			{
				this._coordinates[i] = coordSeq.GetCoordinateCopy(i);
			}
		}

		public DefaultCoordinateSequence(int size)
		{
			this._coordinates = new Coordinate[size];
			for (int i = 0; i < size; i++)
			{
				this._coordinates[i] = new Coordinate();
			}
		}

		public int Dimension
		{
			get
			{
				return 3;
			}
		}

		public Ordinates Ordinates
		{
			get
			{
				return Ordinates.XYZ;
			}
		}

		public Coordinate GetCoordinate(int i)
		{
			return this._coordinates[i];
		}

		public Coordinate GetCoordinateCopy(int i)
		{
			return new Coordinate(this._coordinates[i]);
		}

		public void GetCoordinate(int index, Coordinate coord)
		{
			coord.X = this._coordinates[index].X;
			coord.Y = this._coordinates[index].Y;
		}

		public double GetX(int index)
		{
			return this._coordinates[index].X;
		}

		public double GetY(int index)
		{
			return this._coordinates[index].Y;
		}

		public double GetOrdinate(int index, Ordinate ordinate)
		{
			switch (ordinate)
			{
			case Ordinate.X:
				return this._coordinates[index].X;
			case Ordinate.Y:
				return this._coordinates[index].Y;
			case Ordinate.Z:
				return this._coordinates[index].Z;
			default:
				return double.NaN;
			}
		}

		public void SetOrdinate(int index, Ordinate ordinate, double value)
		{
			switch (ordinate)
			{
			case Ordinate.X:
				this._coordinates[index].X = value;
				return;
			case Ordinate.Y:
				this._coordinates[index].Y = value;
				return;
			case Ordinate.Z:
				this._coordinates[index].Z = value;
				return;
			default:
				return;
			}
		}

		public object this[int i]
		{
			get
			{
				return this._coordinates[i];
			}
		}

		public Envelope ExpandEnvelope(Envelope env)
		{
			for (int i = 0; i < this._coordinates.Length; i++)
			{
				env.ExpandToInclude(this._coordinates[i]);
			}
			return env;
		}

		public ICoordinateSequence Reversed()
		{
			Coordinate[] array = new Coordinate[this._coordinates.Length];
			int num = this._coordinates.Length;
			for (int i = 0; i < this._coordinates.Length; i++)
			{
				array[--num] = this._coordinates[i];
			}
			return new DefaultCoordinateSequence(array);
		}

		public object Clone()
		{
			Coordinate[] array = new Coordinate[this._coordinates.Length];
			for (int i = 0; i < this._coordinates.Length; i++)
			{
				array[i] = (Coordinate)this._coordinates[i].Clone();
			}
			return new DefaultCoordinateSequence(array);
		}

		public int Count
		{
			get
			{
				return this._coordinates.Length;
			}
		}

		public int Length
		{
			get
			{
				return this._coordinates.Length;
			}
		}

		public Coordinate[] ToCoordinateArray()
		{
			return this._coordinates;
		}

		public override string ToString()
		{
			if (this._coordinates.Length != 0)
			{
				StringBuilder stringBuilder = new StringBuilder(17 * this._coordinates.Length);
				stringBuilder.Append('(');
				stringBuilder.Append(this._coordinates[0]);
				for (int i = 1; i < this._coordinates.Length; i++)
				{
					stringBuilder.Append(", ");
					stringBuilder.Append(this._coordinates[i]);
				}
				stringBuilder.Append(')');
				return stringBuilder.ToString();
			}
			return "()";
		}

		private readonly Coordinate[] _coordinates;
	}
}
